package puzzle.akari.view.swing;

import java.awt.Color;
import java.awt.Graphics2D;

import puzzle.akari.data.AkariBoard;
import puzzle.akari.data.BlockNumber;
import puzzle.common.view.swing.AbstractPuzzleViewPanel;

public class AkariViewPanel extends AbstractPuzzleViewPanel<AkariBoard> {

	private static final long serialVersionUID = 1L;

	@Override
	protected void paintBoard(Graphics2D g2, AkariBoard b) {
		int r = (int) (m_cellSize * 0.4);
		for (int x = 0; x < b.width; x++) {
			for (int y = 0; y < b.height; y++) {
				int x0 = x * m_cellSize;
				int y0 = y * m_cellSize;
				switch (b.getBlockNumber(x, y)) {
				case BlockNumber.NON_BLOCK:
					if (b.isLit(x, y) || b.isLightPut(x, y)) {
						g2.setColor(Color.YELLOW);
						g2.fillRect(x0, y0, m_cellSize, m_cellSize);
					}
					if (b.isLightPut(x, y)) {
						int x1 = x0 + m_cellSize / 2 - r;
						int y1 = y0 + m_cellSize / 2 - r;
						g2.setStroke(m_thinStroke);
						g2.setColor(b.isAssumed(x, y) ? Color.RED : Color.WHITE);
						g2.fillOval(x1, y1, r * 2, r * 2);
						g2.setColor(Color.BLACK);
						g2.drawOval(x1, y1, r * 2, r * 2);
					}
					if (b.isLightExplicitlyForbidden(x, y)) {
						g2.setColor(Color.BLACK);
						drawCross(g2, x0 + m_cellSize / 2, y0 + m_cellSize / 2, m_dotSize);
					}
					break;
				case BlockNumber.UNNUMBERED_BLOCK:
					g2.setColor(Color.BLACK);
					g2.fillRect(x0, y0, m_cellSize, m_cellSize);
					break;
				default:
					g2.setColor(Color.BLACK);
					g2.fillRect(x0, y0, m_cellSize, m_cellSize);
					g2.setColor(Color.WHITE);
					drawStringInCell(g2, x, y, String.valueOf(b.getBlockNumber(x, y)));
					break;
				}
			}
		}

		drawGrid(g2, b);
	}
}
